package com.example.huhu.chd4_01;

import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;

public class MainActivity extends AppCompatActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        RadioGroup RG_OS;
        RadioButton RG_OS_RB1, RG_OS_RB2, RG_OS_RB3;
        Button button_submit, button_back;
        //根据xml定义生成取得RadioGroup,RadioButton、Button对象
        RG_OS = (RadioGroup) findViewById(R.id.RG_OS);
        RG_OS_RB1 = (RadioButton) findViewById(R.id.RG_OS_RB1);
        RG_OS_RB2 = (RadioButton) findViewById(R.id.RG_OS_RB2);
        RG_OS_RB3 = (RadioButton) findViewById(R.id.RG_OS_RB3);
        button_submit = (Button) findViewById(R.id.button_submit);
        //使用setOnClickListener 注册按钮单击事件监听器
        button_submit.setOnClickListener(new ButtonClickListener());


    }

    //定义按钮　button_submit 单击监听器。　当单击button_submit按钮时,onClick 方法被调用
    class ButtonClickListener implements View.OnClickListener {
        public void onClick(View arg0) {
            //新建一个Intent对象
            Intent myintent = new Intent();
            //指定Intent对象的目标组件是Activity2
            myintent.setClass(MainActivity.this, Activity2.class);
            //利用startActivity()启动新的Activity，即Activity2
            MainActivity.this.startActivity(myintent);
            //关闭当前的Activity
            MainActivity.this.finish();


        }
    }
}
